package com.example.hhh.controller;

import com.example.hhh.model.Business;
import com.example.hhh.service.BusinessService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/businesses")
public class BusinessController {

    private final BusinessService businessService;

    public BusinessController(BusinessService businessService) {
        this.businessService = businessService;
    }

    @PostMapping
    public ResponseEntity<Business> createBusiness(@RequestBody Business business) {
        return ResponseEntity.ok(businessService.createBusiness(business));
    }

    @GetMapping("/{id}")
    public ResponseEntity<Business> getBusinessById(@PathVariable Integer id) {
        return ResponseEntity.ok(businessService.getBusinessById(id));
    }

    @GetMapping
    public ResponseEntity<Page<Business>> getAllBusinesses(Pageable pageable) {
        return ResponseEntity.ok(businessService.getAllBusinesses(pageable));
    }

    @GetMapping("/by-type")
    public ResponseEntity<List<Business>> getBusinessesByType(
            @RequestParam String type) {
        return ResponseEntity.ok(businessService.findByBusinessType(type));
    }

    @GetMapping("/by-cost-range")
    public ResponseEntity<List<Business>> getBusinessesByCostRange(
            @RequestParam Double min,
            @RequestParam Double max) {
        return ResponseEntity.ok(
                businessService.findBusinessByCostRange(min, max));
    }
}